import { EVENT_NAME_ENUM, BUNDLE_TYPE_ENUM } from "../../../../script/base/EnumIndex";
import { AudioManager } from "../../../../script/manager/AudioManager";
import { EventManager } from "../../../../script/manager/EventManager";
import { LevelManager, LEVEL_TYPE } from "../../../../script/manager/LevelManager";
import { UIManager } from "../../../../script/manager/UIManager";
import HomeUI from "../../../../script/uiPanel/HomeUI";




const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {


    /** 物品框 */
    @property(cc.Node)
    wupinkuang: cc.Node = null;


    /** 物品名称 */
    @property(cc.Label)
    wupinname: cc.Label = null;


    /** 再通关 */
    @property(cc.Label)
    zaitongguan: cc.Label = null;

    start() {
        this.node.getChildByName("mask").on("click", () => {
            this.clickBtnClose();
        })
    }
    onLoad() {
        EventManager.ins.on(EVENT_NAME_ENUM.OPEN_UI, this.openUI, this);
    }
    protected onDestroy(): void {
        EventManager.ins.off(EVENT_NAME_ENUM.OPEN_UI, this.openUI, this);
    }
    clickBtnClose() {
        AudioManager.playClick();
        UIManager.ins.close();
    }

    clickLevelClose() {
        AudioManager.playClick();
        UIManager.ins.closeAll();
        EventManager.ins.off(EVENT_NAME_ENUM.OPEN_UI, this.openUI, this);
        LevelManager.ins.selectLevelType = LEVEL_TYPE.ALL_TYPE;
        UIManager.ins.showUI("LevelUI", BUNDLE_TYPE_ENUM.HOME);
    }
    openUI(data) {
        console.log(data);

        for (let index = 0; index < this.wupinkuang.children.length; index++) {
            const element = this.wupinkuang.children[index];
            if (element.name == data.name) {
                element.active = true; 
            } else {
                element.active = false;
            }
        }


        this.wupinname.string = data.name;
        for (const key in HomeUI.shengjidian) {
            const element2 = HomeUI.shengjidian[key];
            if (element2[1][data.name]) {
                this.zaitongguan.string = "再通过" + data.num + "关"
                break;
            }
        }
    }

}
